﻿#pragma once

#include <string>
#include <vector>

namespace LuaGui {
	class Paint {
	public:
		Paint();
		~Paint();

		virtual void DrawPoint(double x, double y) = 0;
		virtual void MoveTo(double x, double y) = 0;
		virtual void LineTo(double x, double y) = 0;
		virtual void DrawLine(double x1, double y1, double x2, double y2, bool stroke) = 0;
		virtual void DrawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, bool fill = true, bool stroke = false) = 0;
		virtual void DrawCurve(double x1, double y1, double x2, double y2, double x3, double y3, bool fill = true, bool stroke = false) = 0;
		virtual void DrawRectangle(double x, double y, double w, double h, bool fill = true, bool stroke = false) = 0;
		virtual void DrawArc(double cx, double cy, double radius, double angle1, double angle2, bool fill = true, bool stroke = false) = 0;
		virtual void DrawPolygon(std::vector<double>& points, bool fill = true, bool stroke = false) = 0;
		virtual void DrawText(double x, double y, const char* utf8) = 0;
		virtual void Stroke() = 0;
		virtual void Fill() = 0;

		virtual double GetTextWidth(const char* utf8, double font_size) = 0;
		virtual void DrawNineImage(double x, double y, double w, double h, const std::string& utf8_png_filename, double l = 0, double t = 0, double r = 0, double b = 0) = 0;
		virtual void DrawImage(double dx, double dy, double dw, double dh, const std::string& utf8_png_filename, double sx = 0, double sy = 0, double sw = -1, double sh = -1, bool is_scale = false) = 0;


		// pixmal data
		virtual void Clear() = 0;  // 清除数据
		virtual void Flush() = 0;
		virtual unsigned char* GetData() = 0;
		virtual void Dump() {};
		virtual void WriteToPng(const char* utf8_filename) = 0;

		// Transformation
		virtual void Translate(double tx, double ty) = 0;
		virtual void Scale(double sx, double sy) = 0;
		virtual void Rotate(double angle) = 0;
		//virtual void Transform() = 0;

		virtual void Clip() = 0;
		virtual void Save() = 0;
		virtual void Restore() = 0;
		virtual int GetColorByteCount() { return 4; }

		virtual bool SetFont(std::string font_file) = 0;
		virtual bool SetFont(unsigned char* data, uint32_t size) = 0;

	public:
		void DrawText(double x, double y, double w, double h, const char* utf8, const int x_align, const int y_align, bool is_clip);
		void DrawString(double x, double y, double w, double h, const char* utf8, const int x_align, const int y_align, bool is_clip) { DrawText(x, y, w, h, utf8, x_align, y_align, is_clip); }

		// pen brush
		void SetBrushColor(unsigned int brush_color) { m_brush_color = brush_color; }
		void SetBrushColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xff) { m_brush_color = GetColorByRGBA(r, g, b, a); };
		void SetPenColor(unsigned int pen_color) { m_pen_color = pen_color; }
		void SetPenColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xff) { m_pen_color = GetColorByRGBA(r, g, b, a); };
		void SetLineWidth(unsigned int line_width) { m_line_width = line_width; }
		unsigned int GetBrushColor() { return m_brush_color; }
		unsigned int GetPenColor() { return m_pen_color; }
		unsigned int GetLineWidth() { return m_line_width; }

		// font
		void SetFontColor(unsigned int color) { m_font_color = color; }
		void SetFontColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xff) {  }
		unsigned int GetFontColor() { return m_font_color; }
		void SetFontSize(unsigned int font_size) { m_font_size = font_size; }
		unsigned int GetFontSize() { return m_font_size; }

		unsigned int GetColorByRGBA(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0, unsigned char a = 0xff);
		void GetRGBAByColor(unsigned int color, unsigned char& r, unsigned char& g, unsigned char& b, unsigned char& a);

	public:
		//static unsigned int COLOR_R_MARK;
		//static unsigned int COLOR_G_MARK;
		//static unsigned int COLOR_B_MARK;
		//static unsigned int COLOR_A_MARK;

	protected:
		unsigned int m_brush_color;
		unsigned int m_pen_color;
		unsigned int m_line_width;
		unsigned int m_font_color;
		unsigned int m_font_size;
	};
}
